//index.js
//获取应用实例
const app = getApp();
const drawCanvas = require('../../utils/drawcanvas.js');
import {
   downloadCanvasImgMatter,
   wxxGetThisTime,
} from "../../utils/wxxmethod.js";
const REG = require("../../utils/reglib.js");
Page({

   /**
    * 页面的初始数据
    */
   data: {
      loadingMask: false,
      cOpt: {
         id: "canvas-name",
         width: 300,
         height: 377,
      },
      systemInfo: app.data.systemInfo,
      tabConfig: {
         height: 100,
         index: 0,
         list: [{
               "text": "首页",
               "iconPath": "../assets/images/tab/tab1-1.png",
               "selectedIconPath": "../assets/images/tab/tab1-2.png"
            },
            {
               "text": "发起抽奖",
               "iconPath": "../assets/images/tab/tab2-1.png",
               "selectedIconPath": "../assets/images/tab/tab2-2.png"
            },
            {
               "text": "我的",
               "iconPath": "../assets/images/tab/tab3-1.png",
               "selectedIconPath": "../assets/images/tab/tab3-2.png"
            }
         ]
      },
   },
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: function(options) {
      this.data['ctx'] = wx.createCanvasContext(this.data.cOpt.id);
      let num = 20181130;
      console.log('phone number reg：', REG.datesReg(num,'YYMMDD'))
   },

   onShow() {
      let that = this,
         ctx = that.data.ctx,
         downFill = {};
      return;
      downFill['avatarUrl'] = 'https://wx.qlogo.cn/mmopen/vi_32/TVVNKNVV8ZQ0gDafXAyAXXicv5cvee3iaNgSC6E7sRcx7jUZHs9yYyhadZszRibvovnpvx5v4aAjpBjld1BZheXpw/132';
      downFill['banner'] = 'https://ohudong.cztv.com/zgltv/star/tuji/ouxsfs2rvxq131890.jpg';
      downFill['codeimg'] = 'https://xcx-img.vdailian.com/mxxsl/qrcode/145241541656613.png';
      downloadCanvasImgMatter(downFill, '3', (res) => {
         wx.showLoading({
            title: '海报生成中...',
         })
         console.log('下载canvas返回成功', res)
         drawCanvas.drawCanvasBgColor(that.data.cOpt, '#f44b6e', that.data.cOpt.width, that.data.cOpt.height, that);
         drawCanvas.drawText(that.data.cOpt, "标题", 20, 240, '#ffffff', 18, 'left', that);
         drawCanvas.drawLongText(that.data.cOpt, "首先社保包含五险，分别为养老保险、医疗保险、失业保险、工伤保险。", 30, 265, '#ffffff', 16, 'left', that);
         drawCanvas.drawImage(that.data.cOpt, res.banner, 0, 0, that.data.cOpt.width, 400 / 2, that);
         drawCanvas.drawAvatar(that.data.cOpt, 60, 335, 36, downFill.codeimg, 25, 301, 68, 68, that);
         drawCanvas.drawText(that.data.cOpt, "长按二维码识别小程序", 100, 350, '#ffffff', 14, 'left', that);
         ctx.draw(false, () => {
            console.log('绘制完成')
            drawCanvas.canvasExportImage(that.data.cOpt, (exfile) => {
               console.log('画布导出success：', exfile)
               // drawCanvas.authorizeCheck('writePhotosAlbum', (res) => {
               //    console.log('授权校验成功')
               //    drawCanvas.saveImageToPhotosAlbum(exfile,(res)=>{
               //       console.log('资源保存成功')
               //    },(res)=>{});
               // }, () => {});
            }, (res) => {});
         });
      }, (res) => {});

   },
})